//config.treeFrameId与显示列表框无关只有管理时的增删改有关
function Node(id, pid, name, url, title, target, childCount, showCtrl, remark,
		icon) {

	this.id = id;

	this.pid = pid;

	this.name = name;

	this.url = url;

	this.title = title;

	this.target = target;

	this.showCtrl = showCtrl ? showCtrl : true;

	this.remark = remark;

	this.childCount = childCount ? childCount : 0;

	this.icon = icon;

	this.iconOpen = icon;

	this._isOpened = false;

	this._isSelected = false;

	this._lastOfSameLevel = false;

	this._addressIndex = 0;

	this._parentNode;

	this._hasChild = childCount > 0 ? true : false;

};
function iTree(objName) {
	this.config = {

		target : "_self",

		useFolderLinks : true,

		useSelection : true,

		useCookies : true,

		useLines : true,

		useIcons : true,

		useRootIcon : true,

		usePlusMinusIcons : true,

		useMouseover : true,

		useTreeIdInNodeClass : false,

		useLevelInNodeClass : false,

		useRadio : false,

		useCheckbox : false,

		treeNodeClass : null,

		reBuildTree : null,

		loadFloatTree : null,

		floatTreeId : null,

		descHiddenId : null,

		descTextBoxId : null,

		isValue : false,

		isdelay : false,

		isclientDelay : false,

		closeSameLevel : false,

		inOrder : false,

		showRootIco : true,

		showOrder : false,

		orderURL : null,

		treeFrameId : null,

		loadingString : "数据加载中.....",

		imageDir : resource + "/system/images/treeimg"
	};

	this.icon = {

		root : this.config.imageDir + '/base.gif',

		folder : this.config.imageDir + '/folder.gif',

		folderOpen : this.config.imageDir + '/folderopen.gif',

		node : this.config.imageDir + '/page.gif',

		nolineNode : this.config.imageDir + '/nolinepage.gif',

		empty : this.config.imageDir + '/empty.gif',

		line : this.config.imageDir + '/line.gif',

		join : this.config.imageDir + '/join.gif',

		joinBottom : this.config.imageDir + '/joinbottom.gif',

		plus : this.config.imageDir + '/plus.gif',

		plusBottom : this.config.imageDir + '/plusbottom.gif',

		minus : this.config.imageDir + '/minus.gif',

		minusBottom : this.config.imageDir + '/minusbottom.gif',

		nlPlus : this.config.imageDir + '/nolines_plus.gif',

		nlMinus : this.config.imageDir + '/nolines_minus.gif'
	};

	this.interval = null;

	this.currentSelectId = new Object();

	this.floatTreeFrameId = null;// read only

	this.obj = objName;

	this.aNodes = [];

	this.aIndent = [];

	this.root = new Node(-1);

	this.selectedNodeIndex = null;

	this.selectedFound = false;

	this.completed = false;
};
iTree.prototype.resetIcon = function() {
	this.icon.root = this.config.imageDir + '/base.gif';

	this.icon.nolineroot = this.config.imageDir + '/nolinebase.gif';

	this.icon.folder = this.config.imageDir + '/folder.gif';

	this.icon.folderOpen = this.config.imageDir + '/folderopen.gif';

	this.icon.node = this.config.imageDir + '/page.gif';

	this.icon.nolineNode = this.config.imageDir + '/nolinepage.gif';

	this.icon.empty = this.config.imageDir + '/empty.gif';

	this.icon.line = this.config.imageDir + '/line.gif';

	this.icon.join = this.config.imageDir + '/join.gif';

	this.icon.joinBottom = this.config.imageDir + '/joinbottom.gif';

	this.icon.plus = this.config.imageDir + '/plus.gif';

	this.icon.plusBottom = this.config.imageDir + '/plusbottom.gif';

	this.icon.minus = this.config.imageDir + '/minus.gif';

	this.icon.minusBottom = this.config.imageDir + '/minusbottom.gif';

	this.icon.nlPlus = this.config.imageDir + '/nolines_plus.gif';

	this.icon.nlMinus = this.config.imageDir + '/nolines_minus.gif';

};
iTree.prototype.addremark = function(id, pid, name, url, title, remark) {
	this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title,
			"_self", undefined, true, remark);

};
iTree.prototype.add = function(id, pid, name, url, title, target, childCount,
		showCtrl, remark, icon) {

	this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title,
			target, childCount, showCtrl, remark, icon);

};

iTree.prototype.openAll = function() {

	this.oAll(true);

};
iTree.prototype.closeAll = function() {

	this.oAll(false);

};

iTree.prototype.toString = function() {

	var str = '<div class="iTree">\n';

	if (document.getElementById) {

		if (this.config.useCookies)
			this.selectedNodeIndex = this.getSelectedAi();

		str += this.addNode(this.root);

	} else
		str += 'Browser not supported.';

	str += '</div>';
	if (!this.selectedFound)
		this.selectedNodeIndex = null;

	this.completed = true;

	return str;

};
iTree.prototype.delete_click = function() {
	alert('delete_click事件未定义!');
};
iTree.prototype.DeleteNode = function(currentNode) {
	if (!currentNode) {
		currentNode = this.aNodes[this.getSelectedAi()];
	}
	this.aNodes.splice(currentNode._addressIndex, 1);
	this.clearSelectedNode();
	$(this.config.treeFrameId).innerHTML = this.toString();
	this.clearFloatFrame();
};
iTree.prototype.AppendNode = function(newNode) {
	this.aNodes.push(newNode);
	$(this.config.treeFrameId).innerHTML = this.toString();
};

iTree.prototype.UpdateNode = function(newNode, currentNode) {
	if (!currentNode) {
		currentNode = this.aNodes[this.getSelectedAi()];
	}
	if (currentNode.pid != newNode.pid) {
		this.DeleteNode(currentNode);
		this.AppendNode(newNode);
	} else {
		this.aNodes[this.getSelectedAi()] = newNode;
	}
	$(this.config.treeFrameId).innerHTML = this.toString();
};
iTree.prototype.showOrder = function(e) {
	if (this.config.showOrder) {

		var orderDiv = $("orderDiv");
		if (orderDiv) {
			document.body.removeChild(orderDiv);
		}
		e = (e || window.event);
		var srcObject = e.srcElement || e.target;
		var addressIndex = srcObject.id.substring(this.obj.length + 1);
		var currentNode = this.aNodes[addressIndex];
		if (currentNode.pid != -1) {
			orderDiv = $c("div");
			orderDiv.id = "orderDiv";
			orderDiv.style.cssText = "position:absolute;padding:5px;border:#ff9900 1px solid;width:80px;text-align:center;background:#ffffff;";
			orderDiv.innerHTML = '<div id="'
					+ addressIndex
					+ '" onclick="'
					+ this.obj
					+ '.delete_click(parseInt(this.id));";'
					+ this.obj
					+ ".clearFloatFrame();\" style='width:78px;border:#ff9900 1px solid;line-height:30px;text-align:center;margin:1px;cursor:pointer' onclick=\"alert('删除')\";>删除</div>"
					+ "<div style=\"border:#ccc 1px dotted;width:80px;height:150px;overflow:auto;\">当前位置<br/>第"
					+ "<span id=\"currentOrderNo\" style=\"font-size:12pt;color:#ff9900;font-weight:bold;\"></span>位<br/>可以转至<br/>"
					+ "<div  id=\"OrderList\" style=\"border:#ff9900 1px solid;padding:5px;width:60px; background:#ffffff\"></div></div>";
			document.body.appendChild(orderDiv);
			orderDiv.onclick = function(e) {
				jevent.cancelBubble(e);
			};
			orderDiv.style.left = position.getAbsoluteLeftPosByCtrl(srcObject)
					+ srcObject.offsetWidth;
			orderDiv.style.top = position.getAbsoluteTopPosByCtrl(srcObject)
					+ srcObject.offsetHeight;

			var selectHTML = $("OrderList");
			var pNode = currentNode._parentNode;
			var index = 0;
			var currentIndex = 0;
			var listHTML = "<ul style=\"list-style-type:none;margin:0px;padding:0px; \">";
			for (var i = 0; i < this.aNodes.length; i++) {
				if (this.aNodes[i].pid == pNode.id) {

					if (this.aNodes[i].id == currentNode.id) {
						currentIndex = ++index;
					} else {
						index++;
						listHTML += "<li onclick=\""
								+ this.obj
								+ ".Order("
								+ addressIndex
								+ ",this.value)\" value=\""
								+ index
								+ "\" style=\"border:#ccc 1px dotted;line-height:30px;text-align:center;margin:1px;cursor:pointer;\">第<span style='color:red;font-weight:bold;'>"
								+ index + "</span>位</li>";

					}
					if (this.aNodes[i]._lastOfSameLevel) {
						break;
					}
				}
			}
			listHTML += "</ul>";
			selectHTML.innerHTML = listHTML;
			$("currentOrderNo").innerHTML = currentIndex;
		} else {
			this.clearFloatFrame();
		}
	}
};
iTree.prototype.Order = function(srcAddressIndex, descNo) {

	var srcNode = this.aNodes[srcAddressIndex];
	var srcNo = $("currentOrderNo").innerHTML;
	var postString = "uuid=" + srcNode.id + "&descNo=" + descNo;
	var iTreeObj = this;
	ajax.req("POST", this.config.orderURL, function(xmlHttpRequest) {
		if (xmlHttpRequest.responseText.indexOf("error") == -1) {
			var descNodes = new Array();
			var descNode = null;

			var srcParentNode = srcNode._parentNode;
			var childNo = 0;
			for ( var i = 0; i < iTreeObj.aNodes.length; i++) {
				if (iTreeObj.aNodes[i].pid == srcParentNode.id) {
					childNo++;
					if (childNo == descNo) {
						descNode = iTreeObj.aNodes[i];
						break;
					}
				}
			}
			iTreeObj.aNodes.splice(srcAddressIndex, 1);
			for (i = 0; i < iTreeObj.aNodes.length; i++) {
				if (iTreeObj.aNodes[i].id == descNode.id) {
					if (descNo > srcNo) {
						descNodes.push(iTreeObj.aNodes[i]);
					}
					descNodes.push(srcNode);
					if (descNo < srcNo) {
						descNodes.push(iTreeObj.aNodes[i]);
					}
				} else {
					descNodes.push(iTreeObj.aNodes[i]);
				}
			}
			iTreeObj.aNodes = descNodes;
			$(iTreeObj.config.treeFrameId).innerHTML = iTreeObj.toString();
			iTreeObj.clearFloatFrame();
		} else {
			alert("出错啦!" + xmlHttpRequest.responseText.split(':')[1]);
		}
	}, true, postString);
};
iTree.prototype.addNode = function(pNode) {

	var str = '';

	var n = 0;

	if (this.config.inOrder)
		n = pNode._addressIndex;
	for (n; n < this.aNodes.length; n++) {
		if (this.aNodes[n] != null && this.aNodes[n].pid == pNode.id) {

			var cn = this.aNodes[n];

			cn._parentNode = pNode;

			pNode.childCount++;

			cn._addressIndex = n;

			this.setCS(cn);

			if (!cn.target && this.config.target)
				cn.target = this.config.target;

			if (cn._hasChild && !cn._io && this.config.useCookies)
				cn._isOpened = this.isOpen(cn.id);

			if (!this.config.useFolderLinks && cn._hasChild)
				cn.url = null;

			if (this.config.useSelection && cn.id == this.getSelectedId()) {

				cn._isSelected = true;

				this.selectedNodeIndex = n;

				this.selectedFound = true;

			}
			// 因node中调用addNode()函数则为递归。
			if (this.config.showRootIco) {
				str += this.node(cn, n);
			} else {
				this.node(cn, n);
			}
			// 如果当前节点是当前父节点的最后一个儿子节点则退出遁环
			if (cn._lastOfSameLevel)
				break;

		}

	}
	return str;

};

// 实例化一个节点对象
iTree.prototype.node = function(node, nodeId) {
	// 获得缩进字符串
	var classNum = "";
	if (this.config.treeNodeClass)
		classNum += this.config.treeNodeClass;
	else if (this.config.useTreeIdInNodeClass)
		classNum += this.obj.substring(0, 1).toUpperCase()
				+ this.obj.substring(1);
	if (this.config.useLevelInNodeClass)
		classNum += (this.aIndent.length > 1 ? 3 : (this.aIndent.length + 1));
	var str = '<div';
	if (this.config.useRootIcon || node.pid != this.root.id)
		str += ' class="iTreeNode' + classNum + '"';
	if (this.config.useMouseover) {
		str += ' onmouseover="this.className=\'iTreeNodeHover' + classNum
				+ '\';" onmouseout="this.className=\'iTreeNode' + classNum
				+ '\'" ';
	}
	str += 'id="node' + this.obj + nodeId + '"  >' + this.indent(node, nodeId);
	if (this.config.useIcons) {

		if (this.config.useLines) {
			node.icon = (this.root.id == node.pid) ? this.icon.root
					: ((node._hasChild) ? this.icon.folder : this.icon.node);
			node.iconOpen = (this.root.id == node.pid) ? this.icon.root
					: (node._hasChild) ? this.icon.folderOpen : this.icon.node;
		} else if (!node.icon) {
			node.iconOpen = node.icon = node._hasChild ? this.icon.nolinefolder
					: this.icon.nolinenode;
		}
		if (this.config.useRootIcon || node.pid != this.root.id) {
			str += '<img '
					+ (this.config.showOrder ? ' onmouseover="' + this.obj
							+ '.showOrder(event)"' : '') + ' id="i' + this.obj
					+ nodeId + '" src="'
					+ ((node._isOpened) ? node.iconOpen : node.icon)
					+ '" alt="" align="absMiddle"/>';
		}
		if ((node.showCtrl && node.pid != -1)
				|| (node.pid == -1 && this.userRootIcon == true)) {
			if (this.config.useRadio) {
				str += '<input style="line-height:15px;height:15px;border:0px;" type="radio" name="iTreerdo" id="r'
						+ this.obj
						+ nodeId
						+ '" onclick="javascript:'
						+ this.obj
						+ '.getRadioSelected('
						+ nodeId
						+ ');'
						+ this.obj
						+ '.s('
						+ nodeId
						+ ');" value="'
						+ node.id
						+ '"/>';
			}
			if (this.config.useCheckbox == true) {
				str += '<input style="line-height:15px;height:15px;border:0px;" type="checkbox" name="iTreecbx" id="c'
						+ this.obj
						+ nodeId
						+ '" onclick="javascript:'
						+ this.obj
						+ '.selectCheckbox('
						+ nodeId
						+ ');" value="' + node.id + '"/>';
			}
		}
	}

	if (node.url) {

		str += '<a ondblclick="javascript:'
				+ this.obj
				+ '.dbs('
				+ nodeId
				+ ');" id="s'
				+ this.obj
				+ nodeId
				+ '" class="'
				+ ((this.config.useSelection) ? ((node._isSelected ? 'nodeSel'
						: 'node')) : 'node') + '" href="' + node.url + '"';

		if (node.title)
			str += ' title="' + node.title + '"';
		if (node.target)
			str += ' target="' + node.target + '"';

		if (this.config.useSelection
				&& ((node._hasChild && this.config.useFolderLinks) || !node._hasChild)) {
			str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');';
		}
		str += (this.config.usePlusMinusIcons ? ''
				: (node._hasChild && node._parentNode.id != -1 ? (this.obj
						+ '.o(' + nodeId + ')') : ''))
				+ '">';
	}

	else if ((!this.config.useFolderLinks || !node.url) && node._hasChild
			&& node.pid != this.root.id)

		str += '<a href="javascript: ' + this.obj + '.o(' + nodeId
				+ ');" class="node">';

	str += '<span id="ntext' + this.obj + nodeId + '">' + node.name + '</span>';

	if (node.url
			|| ((!this.config.useFolderLinks || !node.url) && node._hasChild))
		str += '</a>';

	str += '</div>';

	if (node._hasChild) {

		str += '<div id="d'
				+ this.obj
				+ nodeId
				+ '" class="clip" style="display:'
				+ ((this.root.id == node.pid || node._isOpened) ? 'block'
						: 'none') + ';">';
		// 如果不是动态加载
		if (!this.config.isdelay && !this.config.isclientDelay) {
			str += this.addNode(node);
		}
		// 延迟加载子节点(前一条件针对打开的所有非顶级节点，后一条件针对根节点)
		// 是否打开在缓存中取
		else if ((node._isOpened && node.pid != -1) || (node.pid == -1)) {
			str += this.addNode(node);
		}

		str += '</div>';
	}
	this.aIndent.pop();

	return str;

};

// 生成缩进图片
iTree.prototype.indent = function(node, nodeId) {

	var str = '';

	if (this.root.id != node.pid) {

		for ( var n = 0; n < this.aIndent.length; n++) {
			str += '<img src="'
					+ ((this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line
							: this.icon.empty) + '" alt="" />';
		}
		// 因为是递归填加节点，所以用堆栈。先将节点的缩进状态压入栈，等节点填加完成后再弹出栈。
		// 所以当树的层次为多层时，栈中也同样有相同层次的状态信息。如果为是普通节点则画|如果是同父节点的最小兄弟节点则画空格
		node._lastOfSameLevel ? this.aIndent.push(0) : this.aIndent.push(1);
		if (!this.config.usePlusMinusIcons) {
			str += '<img style="width:0px;height:0px;" id="j' + this.obj
					+ nodeId + '"/>';
		} else {
			if (node._hasChild) {
				str += '<a href="javascript: ' + this.obj + '.o(' + nodeId
						+ ');"><img id="j' + this.obj + nodeId + '" src="';
				if (!this.config.useLines)
					str += (node._isOpened) ? this.icon.nlMinus
							: this.icon.nlPlus;
				else
					str += ((node._isOpened) ? ((node._lastOfSameLevel && this.config.useLines) ? this.icon.minusBottom
							: this.icon.minus)
							: ((node._lastOfSameLevel && this.config.useLines) ? this.icon.plusBottom
									: this.icon.plus));
				str += '"/></a>';
			} else {
				str += '<img id="j'
						+ this.obj
						+ nodeId
						+ '" src="'
						+ ((this.config.useLines) ? ((node._lastOfSameLevel) ? this.icon.joinBottom
								: this.icon.join)
								: this.icon.empty) + '" alt="" />';
			}
		}
	}

	return str;

};

// 设置当前节点状态_hc和ls
iTree.prototype.setCS = function(node) {
	var lastId = null;
	node._hasChild = false;
	node._lastOfSameLevel = false;
	for ( var n = 0; n < this.aNodes.length; n++) {
		// 如果不是动态的则判断是否有子节点
		if (this.config.isdelay == false) {
			if (this.aNodes[n] != null && this.aNodes[n].pid == node.id) {
				node._hasChild = true;
			}
		}
		if (this.aNodes[n] != null && this.aNodes[n].pid == node.pid)
			lastId = this.aNodes[n].id;

	}
	if (lastId == node.id)
		node._lastOfSameLevel = true;

};
iTree.prototype.getAllNameOfNode = function(cn, splitChar) {
	if (!cn) {
		cn = this.aNodes[this.getSelectedAi()];
	}
	var nameArray = new Array();
	var allName = "";
	while (cn.id != -1) {
		if (cn.name.indexOf(':') != -1) {
			nameArray.push(cn.name.split(':')[1]);
		} else {
			nameArray.push(cn.name);

		}
		if (cn._parentNode) {
			cn = cn._parentNode;// 如果cn_p存在，即是静加载因为是动态加载只有addNode后才有该节点信息
		} else {
			cn = this.aNodes[this.getAiById(cn.pid)];
		}
	}
	var cnName;
	splitChar = splitChar ? splitChar : "  ";
	while (nameArray.length != 0) {

		cnName = nameArray.pop();

		allName += cnName + splitChar;
	}

	return allName;
};

// 获取当前选中的节点地址索引只有一个
iTree.prototype.getSelectedAi = function() {

	return this.getAiById(this.getSelectedId());

};
// 获取当前选中的节点ID只有一个
iTree.prototype.getSelectedId = function() {

	var sn;

	if (this.config.useCookies == true) {

		sn = this.getCookie('currentSelect' + this.obj);

	} else {
		sn = this.currentSelectId["currentSelect" + this.obj];

	}

	return (sn) ? sn : null;

};

// 清除当前选中节点
iTree.prototype.clearSelectedNode = function() {
	var now = new Date();

	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);

	this.setCookie('cs' + this.obj, 'cookieValue', yesterday);

	this.currentSelectId["currentSelect" + this.obj] = null;
};
// 设置当前选中的节点
iTree.prototype.setCurrentSelectNode = function(cn) {

	if (this.config.useCookies) {
		this.setCookie('currentSelect' + this.obj, cn.id);

	} else {
		this.currentSelectId["currentSelect" + this.obj] = cn.id;
	}
};
// 选择事件
iTree.prototype.s = function(id) {

	if (!this.config.useSelection)
		return;

	var cn = this.aNodes[id];

	if (cn._hasChild && !this.config.useFolderLinks)
		return;

	if (this.selectedNodeIndex != id) {

		if (this.selectedNodeIndex || this.selectedNodeIndex == 0) {
			// 将之前的选中节点置为普通结点状态
			eOld = document.getElementById("s" + this.obj
					+ this.selectedNodeIndex);

			this.aNodes[this.selectedNodeIndex]._isSelected = false;

			eOld.className = "node";

		}

		eNew = document.getElementById("s" + this.obj + id);

		eNew.className = "nodeSel";

		this.selectedNodeIndex = id;

		cn._isSelected = true;

		this.setCurrentSelectNode(cn);
	}
	if (document.getElementById("r" + this.obj + id)) {
		document.getElementById("r" + this.obj + id).checked = true;
		this.getRadioSelected(id);
	}

	if (document.getElementById("c" + this.obj + id)) {
		var currentcbk = document.getElementById("c" + this.obj + id);
		currentcbk.checked = !currentcbk.checked;
		this.selectCheckbox(id);
	}

	if (this.config.closeSameLevel)
		this.closeLevel(cn);

};

iTree.prototype.dbs = function(nodeId) {
	alert(nodeId);
};
/**
 * 把折叠状态节点的子节点加载到子节点面板中<br>
 * 
 * @param node
 *            节点对象;
 */
iTree.prototype.delayOpen = function(node) {
	var currentTree = this;
	var cn = node;
	var id = node._addressIndex;
	// 延迟加载折叠状态节点的子节点
	if (cn._isOpened == false) {
		// 获取展示子节点的div
		var childrenDIV = document.getElementById('d' + this.obj + id);

		// 该结点从未展开过
		if (childrenDIV != null && childrenDIV.innerHTML == "") {
			var postStr = "ay=true&nodeId=" + cn.id;
			if ($("exceptid").value) {
				postStr += "&exceptid=" + $("exceptid").value;
			}
			ajax
					.req(
							"POST",
							this.config.ajaxURL,
							function(xmlHttpRequest) {
								if (xmlHttpRequest.responseText != "") {
									// alert(xmlHttpRequest.responseText);
									var nodeListJson = xmlHttpRequest.responseText
											.toJson();
									openNodeCallBack(nodeListJson);
									// 将从当前节点到次级根节点之前所有父节点是否是同级节点的最后一个的标志压栈
									var nodeTemp = cn;
									var indentArray = new Array();
									// 循环到次级根节点之前
									while (nodeTemp.pid != -1) {
										indentArray[indentArray.length] = (nodeTemp._lastOfSameLevel) ? 0
												: 1;
										nodeTemp = nodeTemp._parentNode;
									}
									// 反向压栈
									for ( var i = indentArray.length - 1; i >= 0; i--) {
										currentTree.aIndent
												.push(indentArray[i]);
									}
									// 初始化下下级所有结点，并得到所有下一级子节点的html字符串，并将一层孩子写入到页面中
									childrenDIV.innerHTML = currentTree
											.addNode(cn);
									// 清除临时深度
									for ( var i = 0; i < indentArray.length; i++) {
										currentTree.aIndent.pop();
									}
								}
							}, true, postStr);
		}
	}
};
iTree.prototype.clientDelayOpen = function(node, isFresh) {
	var cn = node;
	var id = node._addressIndex;
	// 延迟加载折叠状态节点的子节点
	if (cn._isOpened == false || isFresh) {
		// 获取展示子节点的div
		var childrenDIV = document.getElementById('d' + this.obj + id);

		// 该结点从未展开过
		if (childrenDIV != null && childrenDIV.innerHTML == "" || isFresh) {
			// 将从当前节点到次级根节点之前所有父节点是否是同级节点的最后一个的标志压栈
			var nodeTemp = cn;
			var indentArray = new Array();

			// 循环到次级根节点之前
			while (nodeTemp._parentNode.id != this.root.id) {
				indentArray[indentArray.length] = (nodeTemp._lastOfSameLevel) ? 0
						: 1;
				nodeTemp = nodeTemp._parentNode;
			}

			// 反向压栈
			for ( var i = indentArray.length - 1; i >= 0; i--) {
				this.aIndent.push(indentArray[i]);
			}

			// 初始化下下级所有结点，并得到所有下一级子节点的html字符串，并将一层孩子写入到页面中
			childrenDIV.innerHTML = this.addNode(cn);

			// 清除临时深度
			for ( var i = 0; i < indentArray.length; i++) {
				this.aIndent.pop();
			}
		}
	}
};

// 当含有子节点的父节点打开
iTree.prototype.o = function(id) {
	var cn = this.aNodes[id];
	if (this.config.isdelay) {
		this.delayOpen(cn);
	}
	if (this.config.isclientDelay) {
		this.clientDelayOpen(cn);
	}
	this.nodeStatus(!cn._isOpened, id, cn._lastOfSameLevel);

	cn._isOpened = !cn._isOpened;

	if (this.config.closeSameLevel)
		this.closeLevel(cn);

	if (this.config.useCookies)
		this.updateCookie();

};

iTree.prototype.oAll = function(status) {

	for ( var n = 0; n < this.aNodes.length; n++) {

		if (this.aNodes[n] != null && this.aNodes[n]._hasChild
				&& this.aNodes[n].pid != this.root.id) {

			this.nodeStatus(status, n, this.aNodes[n]._lastOfSameLevel);

			this.aNodes[n]._isOpened = status;

		}

	}

	if (this.config.useCookies)
		this.updateCookie();

};

iTree.prototype.getAiById = function(id) {
	for ( var n = 0; n < this.aNodes.length; n++) {

		if (this.aNodes[n] != null && this.aNodes[n].id == id) {

			return n;

		}

	}
	return null;
};
// openTo打开到某某节点(只支持静态)
iTree.prototype.openTo = function(nId, isAi) {

	if (!isAi) {
		nId = this.getAiById(nId);
	}
	if (nId != null) {
		var cn = this.aNodes[nId];

		if (this.config.delay) {
			var openNodeArray = new Array();
			while (cn._parentNode.pid != -1) {
				openNodeArray.push(cn);
				cn = cn._parentNode;
			}
		} else {

			if (cn.pid == this.root.id || !cn._parentNode)
				return;

			cn._isOpened = true;

			if (this.completed && cn._hasChild)
				this.nodeStatus(true, cn._addressIndex, cn._lastOfSameLevel);

			this.openTo(cn._parentNode._addressIndex, true);
		}
	}

};

// 相同父节点中的所有子节点中，关闭除node节点之外的所有兄弟节点
iTree.prototype.closeLevel = function(node) {

	for ( var n = 0; n < this.aNodes.length; n++) {

		if (this.aNodes[n] != null && this.aNodes[n].pid == node.pid
				&& this.aNodes[n].id != node.id && this.aNodes[n]._hasChild) {

			this.nodeStatus(false, n, this.aNodes[n]._lastOfSameLevel);

			this.aNodes[n]._isOpened = false;

			this.closeAllChildren(this.aNodes[n]);
		}
	}
};
// 关闭当前node节点的所有子节点
iTree.prototype.closeAllChildren = function(node) {

	for ( var n = 0; n < this.aNodes.length; n++) {

		if (this.aNodes[n] != null && this.aNodes[n].pid == node.id
				&& this.aNodes[n]._hasChild) {

			if (this.aNodes[n]._isOpened)
				this.nodeStatus(false, n, this.aNodes[n]._lastOfSameLevel);

			this.aNodes[n]._isOpened = false;

			this.closeAllChildren(this.aNodes[n]);
		}
	}
};

// 设置当前节点状态
// status是否打开
// id当前节点地址索引
// bottom是否为相同父节点的最后一个子节点
iTree.prototype.nodeStatus = function(isOpen, nodeIndex, isLastNodeOfSameLevel) {

	eDiv = document.getElementById('d' + this.obj + nodeIndex);

	eJoin = document.getElementById('j' + this.obj + nodeIndex);

	if (this.config.usePlusMinusIcons) {

		eIcon = document.getElementById('i' + this.obj + nodeIndex);

		if (this.config.useIcons) {

			eIcon.src = ((isOpen) ? this.aNodes[nodeIndex].iconOpen
					: this.aNodes[nodeIndex].icon);
		}

		eJoin.src = (this.config.useLines) ?

		((isOpen) ? ((isLastNodeOfSameLevel) ? this.icon.minusBottom
				: this.icon.minus)
				: ((isLastNodeOfSameLevel) ? this.icon.plusBottom
						: this.icon.plus)) :

		((isOpen) ? this.icon.nlMinus : this.icon.nlPlus);
	} else {
		eJoin.src = this.icon.empty;
	}

	eDiv.style.display = (isOpen) ? 'block' : 'none';

};

iTree.prototype.clearCookie = function() {

	var now = new Date();

	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);

	this.setCookie('co' + this.obj, 'cookieValue', yesterday);

	this.setCookie('cs' + this.obj, 'cookieValue', yesterday);

};

iTree.prototype.setCookie = function(cookieName, cookieValue, expires, path,
		domain, secure) {

	document.cookie =

	escape(cookieName) + '=' + escape(cookieValue)

	+ (expires ? '; expires=' + expires.toGMTString() : '')

	+ (path ? '; path=' + path : '')

	+ (domain ? '; domain=' + domain : '')

	+ (secure ? '; secure' : '');

};

// iTree有两个cookieName
// 1、co当前打开的currentOpen
// 2、cs当前选择的currentSelected

iTree.prototype.getCookie = function(cookieName) {

	var cookieValue = '';

	var posName = document.cookie.indexOf(escape(cookieName) + '=');

	if (posName != -1) {

		var posValue = posName + (escape(cookieName) + '=').length;

		var endPos = document.cookie.indexOf(';', posValue);

		if (endPos != -1)
			cookieValue = unescape(document.cookie.substring(posValue, endPos));

		else
			cookieValue = unescape(document.cookie.substring(posValue));

	}

	return (cookieValue);

};

iTree.prototype.updateCookie = function() {

	var str = '';

	for ( var n = 0; n < this.aNodes.length; n++) {

		if (this.aNodes[n] != null && this.aNodes[n]._isOpened
				&& this.aNodes[n].pid != this.root.id) {

			if (str)
				str += '.';

			str += this.aNodes[n].id;

		}

	}

	this.setCookie('currentOpen' + this.obj, str);

};

// [Cookie] Checks if a node id is in a cookie
// 判断节点是否为打开状态
iTree.prototype.isOpen = function(id) {

	var aOpen = this.getCookie('currentOpen' + this.obj).split('.');

	for ( var n = 0; n < aOpen.length; n++)

		if (aOpen[n] == id)
			return true;

	return false;

};

// If Push and pop is not implemented by the browser

if (!Array.prototype.push) {

	Array.prototype.push = function array_push() {

		for ( var i = 0; i < arguments.length; i++)

			this[this.length] = arguments[i];

		return this.length;

	};

};

if (!Array.prototype.pop) {

	Array.prototype.pop = function array_pop() {

		lastElement = this[this.length - 1];

		this.length = Math.max(this.length - 1, 0);

		return lastElement;

	};
};
iTree.prototype.getAllId = function() {
	var idArray = new Array();
	for ( var i = 0; i < this.aNodes.length; i++) {
		idArray.push(this.aNodes[i].id);
	}
	return idArray;
};
iTree.prototype.getAllParentNode = function() {
	var cn = this.aNodes[this.getSelectedAi()];

	var parentNodeIdArray = new Array();
	if (cn) {
		while (cn.id != -1) {
			parentNodeIdArray.push(cn.id);
			cn = cn._parentNode;
		}
	} else {
		parentNodeIdArray.push(0);
	}
	return parentNodeIdArray;
};
iTree.prototype.selectChilds = function(parentIds, currentSelected, length) {

	pids = new Array();
	for ( var n = 0; n < length; n++) {
		if (parentIds.indexOf(this.aNodes[n].pid) != -1) {
			if (this.aNodes[n].showCtrl != false) {
				document.getElementById("c" + this.obj + n).checked = currentSelected;
				pids.push(this.aNodes[n].id);
			}

		}
	}
	if (pids.length != 0) {
		this.selectChilds(pids, currentSelected, length);
	}

};
iTree.prototype.getRadioSelected = function() {
	return null;
};
iTree.prototype.selectCheckbox = function(nodeId) {
	var node = this.aNodes[nodeId];
	var currentSelected=null;
	if (node.selectChild == undefined || node.selectChild == true) {
		currentSelected = document.getElementById("c" + this.obj + nodeId).checked;
		if (currentSelected) {
			var cn = node;
			var c;
			while (cn.id != -1) {
				c = document.getElementById("c" + this.obj + cn._addressIndex);
				if (c)
					c.checked = true;
				cn = cn._parentNode;
			}
		}
		var len = this.aNodes.length;
		var parentIds = new Array();
		for ( var n = 0; n < len; n++) {
			if ((n != nodeId)
					&& (this.aNodes[n] != null && this.aNodes[n].pid == node.id)) {
				if (this.aNodes[n].showCtrl != false) {
					document.getElementById("c" + this.obj + n).checked = currentSelected;
					parentIds.push(this.aNodes[n].id);
				}
			}
		}
		if (parentIds.length != 0) {
			this.selectChilds(parentIds, currentSelected, len);
		}
	}

	try {
		checkBoxClick(node.id, currentSelected);
	} catch (err) {
	}
};
// 字符串格式1,2,3
// Array
iTree.prototype.setChecked = function(checkedId) {

	if (typeof (checkedId) == "string") {
		checkedId = checkedId.split(",");
	}

	var checkBoxList = document.getElementsByName("iTreecbx");
	for ( var n = 0; n < checkBoxList.length; n++) {
		if (checkedId.indexOf(checkBoxList[n].value) != -1) {
			checkBoxList[n].checked = true;
		}
	}
};
iTree.prototype.getAllCheckedTitle = function() {
	var nodes = new Array();
	var checkBoxList = document.getElementsByName("iTreecbx");
	for ( var i = 0; i < checkBoxList.length; i++) {
		if (checkBoxList[i].checked == true) {
			arrayIndex = checkBoxList[i].id.replace('c' + this.obj, '');
			nodes.push(this.aNodes[arrayIndex].title);
		}
	}
	return nodes;
};
iTree.prototype.getAllChecked = function() {
	var nodes = new Array();
	var checkBoxList = document.getElementsByName("iTreecbx");
	for ( var i = 0; i < checkBoxList.length; i++) {
		if (checkBoxList[i].checked == true) {
			arrayIndex = checkBoxList[i].id.replace('c' + this.obj, '');
			nodes.push(this.aNodes[arrayIndex]);
		}
	}
	return nodes;

};
iTree.prototype.getAllCheckedId = function() {
	var nodes = new Array();
	var checkBoxList = document.getElementsByName("iTreecbx");
	for ( var i = 0; i < checkBoxList.length; i++) {
		if (checkBoxList[i].checked == true) {
			nodes.push(checkBoxList[i].value);
		}
	}
	return nodes.join();

};
iTree.prototype.Show = function(e, width, maxHeight) {
	if (!this.floatTreeFrameId) {
		// 根据主树重建用户选择树，未访问数据库
		if (this.config.reBuildTree)
			this.config.reBuildTree();
		// 通过方法loadFloatTree方法建新树
		if ($(this.config.floatTreeId).innerHTML.trim() == ""
				&& typeof (this.config.loadFloatTree) != "undefined") {
			this.config.loadFloatTree();
		}
		e = jevent.getEvent(e);
		var srcObject = e.srcElement || e.target;
		var HTMLObject = document.createElement("DIV");
		HTMLObject.id = this.config.floatTreeId + "Frame";
		HTMLObject.style.cssText = "position:absolute;width:"
				+ width
				+ "px;height:0px;border:#ccc 1px solid;background:#ffffff; padding:1px;text-align:left;overflow:auto;";
		HTMLObject.innerHTML = this.config.loadingString;
		document.body.appendChild(HTMLObject);
		HTMLObject.onclick = function(e) {
			jevent.cancelBubble(e);
		};
		HTMLObject.style.left = (position.getAbsoluteLeftPosByCtrl(srcObject) + 1)
				+ "px";
		HTMLObject.style.top = (position.getAbsoluteTopPosByCtrl(srcObject) + srcObject.offsetHeight)
				+ "px";
		this.interval = window.setInterval(this.obj + ".IntervalShow("
				+ maxHeight + ")", 10);
	}
};
iTree.prototype.IntervalShow = function(maxHeight) {
	var FrameId = this.config.floatTreeId + "Frame";
	// var divWidth=parseInt($(FrameId).style.width.replace("px",""));
	var divHeight = $(FrameId).clientHeight + 15;
	if (divHeight >= maxHeight) {

		this.floatTreeFrameId = FrameId;
		if ($(this.config.floatTreeId)
				&& $(this.config.floatTreeId).innerHTML != "") {
			var treeDiv = $(this.config.floatTreeId);
			$(FrameId).innerHTML = "";
			treeDiv.style.display = "block";
			$(FrameId).appendChild(treeDiv);
			window.clearInterval(this.interval);
		}
	} else {
		$(FrameId).style.height = (divHeight) + "px";
	}
};
iTree.prototype.clearFloatFrame = function() {
	if (this.floatTreeFrameId) {
		var TreeFrame = $(this.floatTreeFrameId);
		// reBuildTree is a function to build floatTree from loaded tree
		if (!this.config.reBuildTree) {
			var tree = $(this.config.floatTreeId);
			tree.style.display = "none";
			document.body.appendChild(tree);
		}
		document.body.removeChild(TreeFrame);
		this.floatTreeFrameId = null;
		window.clearInterval(this.interval);
	}
	if ($("orderDiv")) {
		document.body.removeChild($("orderDiv"));
	}
};
// 编码列表
iTree.prototype.initCodeToolip = function(codePrefix, ajaxUrl) {
	var htmlEvents = "jevent.add($(" + this.obj + ".config.descTextBoxId)"
			+ ",'onchange',function(){" + "if($(" + this.obj
			+ ".config.descTextBoxId).value==''){" + "$(" + this.obj
			+ ".config.descHiddenId).value='';" + "if(typeof(" + this.obj
			+ ".config.valueTextBoxId)!='undefined')" + "{$(" + this.obj
			+ ".config.valueTextBoxId).value='';}}});";
	window.setTimeout(htmlEvents, 0);
	var treeObject = this;
	if ($(treeObject.config.floatTreeId) == null) {
		var floatTree = $c(treeObject.config.floatTreeId);
		floatTree.className = "floatTree";
		document.body.appendChild(floatTree);
	}
	if (!ajaxUrl)
		ajaxUrl = rootPath + "/code/load.do";
	this.dbs = function(nodeIndex) {
		var codeEntity = this.aNodes[nodeIndex].remark;
		$(this.config.descHiddenId).value = codeEntity.Code;
		$(this.config.descTextBoxId).value = codeEntity.Name;
		if (typeof (this.config.valueTextBoxId) != "undefined") {
			$(this.config.valueTextBoxId).value = codeEntity.Value;
		}
		if (this.codeNodeCallBack) {
			this.codeNodeCallBack(codeEntity);
		}
		this.clearFloatFrame();
	};
	treeObject.config.loadFloatTree = function() {
		ajax.req("POST", ajaxUrl, function(xmlHttpRequest) {
			treeObject.aNodes = new Array();
			treeObject.config.imageDir = resource + "/system/treeimg";
			treeObject.resetIcon();
			treeObject.config.usePlusMinusIcons = false;
			treeObject.config.useRootIcon = false;
			if (xmlHttpRequest.responseText != "''") {
				if (xmlHttpRequest.responseText.indexOf("error|") != -1) {
					alert(xmlHttpRequest.responseText.split("|")[1]);
				} else {
					var jsonList;
					jsonList = xmlHttpRequest.responseText.toJson();
					treeObject.add(jsonList[0].ParentUUID, -1, "");
					for (var i = 0; i < jsonList.length; i++) {
						treeObject.add(jsonList[i].UUID,
								jsonList[i].ParentUUID, jsonList[i].Name,
								"javascript:" + treeObject.obj
										+ ".codeNodeClick(" + (i + 1) + ");",
								jsonList[i].Code + "|" + jsonList[i].Name,
								undefined, undefined, undefined, jsonList[i]);
					}
				}
			}
			$(treeObject.config.floatTreeId).innerHTML = treeObject;
		}, true, "loadOption=" + codePrefix);
	};
};
iTree.prototype.codeNodeClick = function(nodeIndex) {
	if (this.aNodes[nodeIndex].childCount == 0) {
		this.dbs(nodeIndex);
	}
};
function getForumType(t) {
	// prompt:"1系统菜单 2系统页面 3控件 4 CMS频道 5 CMS链接 6 CMS内容 7 CMS版块 8 论坛版块"
	var forumTypeName=null;
	switch (parseInt(t)) {
	case 1:
		forumTypeName = "[系统菜单]";
		break;
	case 2:
		forumTypeName = "[系统页面]";
		break;
	case 3:
		forumTypeName = "[控件事件]";
		break;
	}
	return forumTypeName;
}